package LeetCode.NumOffer;

import java.util.Arrays;

/**
 * @author lumin
 * @date 2022/05/12 21:39
 **/
public class NumOffer66 {
    public static int[] constructArr(int[] a) {
        if(a.length <= 1){
            return a;
        }
        int[] b = new int[a.length];
        int sum = 1;
        for (int i = 0; i < a.length - 1; i++) {
            sum = a[i] * sum;
        }
        b[b.length - 1] = sum;
        for (int i = a.length - 2; i >= 0; i--) {
            b[i] = (b[i + 1] / (i + 1)) * (i + 2);
        }
        return b;
    }

    public static void main(String[] args) {
        int[] a = {1,2,3,4,5};
        System.out.println(Arrays.toString(constructArr(a)));
    }
}